/*
 * date: 2021/4/10
 * author: 2012190218 WangChenghua
 * linked with listlink.h
 * --std c++14, MSVC.
 * the head file use separate compilation.
 * */
#include <iostream>
#include <fstream>
#include <string>
#include <cstdio>
#include "listlink.h"
using namespace std;

void DEBUG_Single_List();
void DEBUG_Double_List();
void DEBUG_Circle_List();
void REVERSE_LIST();
void STUDENT_CHECK();

int main(){
    //DEBUG_Single_List();
    //DEBUG_Double_List();
    //DEBUG_Circle_List();
    //REVERSE_LIST();
    STUDENT_CHECK();
}

void DEBUG_Single_List(){
    cout<<"------Single linked list------"<<endl;
    SingleLinkedList<int> test;
    test.InitList();
    cout<<"Enter the data, use -1 to quit."<<endl;
    int buff;
    while(cin>>buff && buff!=-1)    test.Insert_at_tail(buff);
    test.Print();
    cout<<"Enter the position and data in a tuple(just once)"<<endl;
    int pos;cin>>pos>>buff;
    test.Insert_any_pos(pos,buff);
    test.Print();
    cout<<"Enter the pos you want to delete."<<endl;
    cin>>pos;
    test.Delete_pos(pos);
    test.Print();
    cout<<"get pos=1's data: ";test.GetList(1);
    cout<<"get length: "<<test.LengthList()<<endl;
    test.ClearList();
    test.Print();
}
void DEBUG_Double_List(){
    cout<<"------Double linked list------"<<endl;
    DuoLinkedList<int> test;
    test.InitList();
    cout<<"Enter the data, use -1 to quit."<<endl;
    int buff;
    while(cin>>buff && buff!=-1)    test.Insert_at_tail(buff);
    test.Print();
    cout<<"Enter the position and data in a tuple(just once)"<<endl;
    int pos;cin>>pos>>buff;
    test.Insert_any_pos(pos,buff);
    test.Print();
    cout<<"Enter the pos you want to delete."<<endl;
    cin>>pos;
    test.Delete_pos(pos);
    test.Print();
    cout<<"get pos=1's data: ";test.GetList(1);
    cout<<"get length: "<<test.LengthList()<<endl;
    test.ClearList();
    test.Print();
}
void DEBUG_Circle_List(){
    cout<<"------Circle linked list------"<<endl;
    CirLinkedList<int> test{};
    test.InitList();
    int buff;
    cout<<"Enter the data, use -1 to quit"<<endl;
    while(cin>>buff && buff!=-1){
        test.Insert_at_tails(buff);
    }
    test.Print();
    cout<<"Enter the data you want to delete all."<<endl;
    cin>>buff;
    test.Delete_data(buff);
    test.Print();
}
void REVERSE_LIST(){
    cout<<"Enter the data, use -1 to quit!"<<endl;
    SingleLinkedList<int> retest;
    retest.InitList();
    int buff;
    while(cin>>buff && buff!=-1){
        retest.Insert_at_tail(buff);
    }
    retest.Print();
    retest.ReverseList();
    retest.Print();
}
void STUDENT_CHECK(){
    Student stu;
    stu.Readfile();
    string bu;
    cout<<">>> (main)Enter F to find,D for delete,I for insert,P to print,q to quit\n";
    cout<<">>> (main)Enter C for item numbers, W to rewrite to file!!!\n";
    while(cin>>bu && bu[0]!='q'){
        if(bu[0]=='F')  stu.Find();
        else if(bu[0]=='D')  stu.Delete();
        else if(bu[0]=='I') stu.Insert_at_tail();
        else if(bu[0]=='P') stu.Print();
        else if(bu[0]=='W') stu.Writefile();
        else if(bu[0]=='C') cout<<"Has Items:"<<stu.LengthList()<<endl;
        cout<<">>> (main)enter another or q to quit\n";
    }
}